# Maintainer: Marcin Sielski <marcin.sielski@motorolasolutions.com>

_realname=libsrtp
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.6.0
pkgrel=1
pkgdesc="Library for SRTP (Secure Realtime Transport Protocol) (mingw-w64)"
arch=('any')
url='https://github.com/cisco/libsrtp'
license=('BSD-based')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-openssl")
options=('strip' 'staticlibs')
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/cisco/${_realname}/archive/v${pkgver}.tar.gz"
        "0001-DEV_URANDOM-removal.patch"
        "0002-symbolic-link-creation-removal-for-mingw-platform.patch"
        "0003-fix-path-for-getopt_s.patch"
        "words.txt")
sha256sums=('1a3e7904354d55e45b3c5c024ec0eab1b8fa76fdbf4dd2ea2625dad2b3c6edde'
            '54df6101316d8fc29f72af88f600f302becab27bc6373d32a4dd1676e8938afb'
            '6b7893f496a15d9ee02df500b0b3488f2ce6fecf034fbc0a862b91a02adec84e'
            '477a8fc9a4485c106f711423270b44dab4a233e2867f05031f827c9785cddc63'
            '126a4ef38493313edc50b86f90dfdaf7c59ec6c948451eac228f2f3a8ab1a6ed')

prepare() {
  cd $srcdir/${_realname}-${pkgver}
  patch -p2 -i ${srcdir}/0001-DEV_URANDOM-removal.patch
  patch -p2 -i ${srcdir}/0002-symbolic-link-creation-removal-for-mingw-platform.patch  
  patch -p2 -i ${srcdir}/0003-fix-path-for-getopt_s.patch  
}

build() {
  cd "$srcdir"/${_realname}-${pkgver}
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    CFLAGS="-DHAVE_RAND_S=1"

  make
  make shared_library
}

check() {
  cp words.txt "${srcdir}"/build-${CARCH}/test
  cd "${srcdir}"/build-${CARCH}
  make runtest
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"
}
